<?php
require('config.php');

		$sql="select * from `".$oto."_areas` where `areaFlag`='1' and `isShow`='1'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$areas[]=$row;//将取得的所有数据赋值给person_info数组
		}
		$sql="select * from `".$oto."_communitys` where `communityFlag`='1' and `isShow`='1'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$communitys[]=$row;//将取得的所有数据赋值给person_info数组
		}
		$data=array();
		$sheng=0;
		for($i=0;$i<count($areas);$i++)
		{
			if($areas[$i]['parentId']==0)
			{
				//$data[$sheng]=$areas[$i];
				$data[$sheng]['areaId']=$areas[$i]['areaId'];
				$data[$sheng]['areaName']=$areas[$i]['areaName'];
				$areas[$i]['isShow']=0;
				$shi=0;
				for($j=0;$j<count($areas);$j++)
				{
					if($areas[$j]['parentId']==$areas[$i]['areaId'] && $areas[$j]['isShow']==1)
					{
						//$data[$sheng]['list'][$shi]=$areas[$j];
						$data[$sheng]['list'][$shi]['areaId']=$areas[$j]['areaId'];
						$data[$sheng]['list'][$shi]['areaName']=$areas[$j]['areaName'];
						$areas[$j]['isShow']=0;
						$qu=0;
						for($k=0;$k<count($areas);$k++)
						{
							if($areas[$k]['parentId']==$areas[$j]['areaId'] && $areas[$k]['isShow']==1)
							{
								//$data[$sheng]['list'][$shi]['list'][$qu]=$areas[$k];
								$data[$sheng]['list'][$shi]['list'][$qu]['areaId']=$areas[$k]['areaId'];
								$data[$sheng]['list'][$shi]['list'][$qu]['areaName']=$areas[$k]['areaName'];
								$areas[$k]['isShow']=0;
								$shequ=0;
								for($l=0;$l<count($communitys);$l++)
								{
									if($communitys[$l]['areaId1']==$areas[$i]['areaId'] && $communitys[$l]['areaId2']==$areas[$j]['areaId'] && $communitys[$l]['areaId3']==$areas[$k]['areaId'] && $communitys[$l]['isShow']==1)
									{
										//$data[$sheng]['list'][$shi]['list'][$qu]['list'][$shequ]=$communitys[$l];
										$communitys[$l]['isShow']=0;
										$data[$sheng]['list'][$shi]['list'][$qu]['list'][$shequ]['areaId']=$communitys[$l]['communityId'];
										$data[$sheng]['list'][$shi]['list'][$qu]['list'][$shequ]['areaName']=$communitys[$l]['communityName'];
										$shequ++;
									}
								}
								if($shequ==0) $data[$sheng]['list'][$shi]['list'][$qu]['list']=[];
								$qu++;
							}
						}
						if($qu==0) $data[$sheng]['list'][$shi]['list']=[];
						$shi++;
					}
				}
				if($shi==0) $data[$sheng]['list']=[];
				$sheng++;
			}
		}
		if($sheng==0) echo '[]';
		else echo json_encode($data);
?>